package com.kingdee.eas.ec.garden.invite.app;

import org.apache.log4j.Logger;
import javax.ejb.*;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kingdee.bos.*;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.rule.RuleExecutor;
import com.kingdee.bos.metadata.MetaDataPK; //import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.framework.ejb.AbstractEntityControllerBean;
import com.kingdee.bos.framework.ejb.AbstractBizControllerBean; //import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.service.ServiceContext;
import com.kingdee.bos.service.IServiceContext;

import java.lang.String;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.ec.garden.invite.TransInviteBillInfo;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.eas.ec.garden.invite.TransInviteBillCollection;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBillBaseCollection;
import com.kingdee.eas.framework.BillBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.ec.basedata.BaseBillCollection;
import com.kingdee.eas.ec.basedata.EcBillStateEnum;
import com.kingdee.eas.framework.ObjectBaseCollection;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.eas.ec.garden.invite.BaseInviteBillCollection;
import com.kingdee.jdbc.rowset.IRowSet;

public class TransInviteBillControllerBean extends
		AbstractTransInviteBillControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.ec.garden.invite.app.TransInviteBillControllerBean");

	protected List _getInviteBill(Context ctx, Map param) throws BOSException,
			EASBizException {
		Map map = null;
		List list = new ArrayList();
		String projectOrgId = (String) param.get("projectOrgId");
		String supplierId = (String) param.get("supplierId");
		StringBuffer sb = new StringBuffer();

		sb
				.append(
						" select distinct bill.fid id,bill.fnumber number,bill.fname name,bill.fbizDate bizDate,bill.flocalAmount amount,bill.fauditDate auditDate,")
				.append(
						" org.fname_l2 tranName,project.fname_l2 projectName,auditor.fname_l2 userName,supply.fname_l2 supplyName,creator.fname_l2 creatorName ")
				.append(" from T_EC_TransInviteBill bill")
				.append(" left join T_EC_TransInviteEntry entry")
				.append(
						" on bill.fid=entry.fparentid left join T_ORG_Transport org on bill.fProjectorgID=org.fid ")
				.append(
						" left join t_ec_Project project on bill.fprojectid=project.fid")
				.append(
						" left join T_PM_User auditor on bill.fauditorid=auditor.fid")
				.append(
						" left join T_PM_User creator on bill.FCreatorID=creator.fid")
				.append(
						" left join T_BD_Supplier supply on entry.FSupplierID=supply.fid")
				.append(
						" where bill.fprojectOrgid=? and bill.fbillSate=? and entry.fSupplierid=?");
		IRowSet rs = DbUtil.executeQuery(ctx, sb.toString(), new Object[] {
				projectOrgId, EcBillStateEnum.AUDITED_VALUE.toString(),
				supplierId });
		try {
			if (rs != null) {
				while (rs.next()) {
					map = new HashMap();
					map.put("id", rs.getString("id"));
					map.put("name", rs.getString("name"));
					map.put("number", rs.getString("number"));
					map.put("bizDate", rs.getDate("bizDate"));
					map.put("auditDate", rs.getDate("auditDate"));
					map.put("tranName", rs.getString("tranName"));
					map.put("projectName", rs.getString("projectName"));
					map.put("userName", rs.getString("userName"));
					map.put("amount", rs.getString("amount"));
					map.put("creator", rs.getString("creatorName"));
					map.put("supplyName", rs.getString("supplyName"));
					list.add(map);
				}

			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

}